/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa165.machineryrental.service;

import cz.muni.fi.pa165.machineryrental.dto.CustomerDTO;
import cz.muni.fi.pa165.machineryrental.dto.MachineDTO;
import cz.muni.fi.pa165.machineryrental.dto.RentalDTO;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;

/**
 *
 * @author Marian Lorenc, 374122
 */
@PreAuthorize ("hasAnyRole('ROLE_USER,ROLE_ADMIN')")
public interface RentalService {

    /**
     * Reads entity with given identifier from database.
     *
     * @param id Represents unique identifier of rental instance.
     * @return Rental, which has given identifier.
     * @throws IllegalArgumentException Throws if given identifier is null.
     * @throws IllegalStateException Throws if manager is not initialized.
     */
    RentalDTO getById(long id);

    /**
     * Persists giver rental instance to database.
     *
     * @param rental Represents rental to persist to database.
     * @throws IllegalArgumentException Throws if given rental is null.
     * @throws IllegalStateException Throws if manager is not initialized.
     */
    void create(RentalDTO rental);

    /**
     * Updates existing instance with given instance in database.
     *
     * @param rental Given Rental instance to update.
     * @throws IllegalArgumentException Throws if given rental is null.
     * @throws IllegalStateException Throws if manager is not initialized.
     */
    void update(RentalDTO rental);

    /**
     * Removes given rental from database if exists.
     *
     * @param rental Rental to remove from database.
     * @throws IllegalArgumentException Throws if given rental is null.
     * @throws IllegalStateException Throws if manager is not initialized.
     */
    @PreAuthorize ("hasRole('ROLE_ADMIN')")
    void remove(RentalDTO rental);

    /**
     * Load all existing rentals from database and returns them as list.
     *
     * @return All existing rentals from database.
     * @throws IllegalStateException Throws if manager is not initialized.
     */
    List<RentalDTO> findAll();

    /**
     * Returns all existing rentals of machinery for given customer.
     *
     * @param customer CustomerDTO, for which we want list of rented machinery.
     * @return List of machines rented by customer.
     * @throws IllegalArgumentException Throws if given customer is null.
     * @throws IllegalStateException Throws if manager is not initialized.
     */
    List<RentalDTO> findByCustomer(CustomerDTO customer);

    /**
     * Returns all existing rentals of given machine.
     *
     * @param machine MachineDTO, for which we want list of all rentals.
     * @return List of all rentals of given machine.
     * @throws IllegalArgumentException Throws if given machine is null.
     * @throws IllegalStateException Throws if manager is not initialized.
     */
    List<RentalDTO> findByMachine(MachineDTO machine);

    /**
     * Returns all existing rentals of given machine and customer.
     *
     * @param customer CustomerDTO, for which we want list of all rentals.
	 * @param machine MachineDTO, for which we want list of all rentals.
     * @return List of all rentals of given machine.
     * @throws IllegalArgumentException Throws if given machine is null.
	 * @throws IllegalArgumentException Throws if given customer is null.
     * @throws IllegalStateException Throws if manager is not initialized.
     */
    List<RentalDTO> findByCustomerMachine(CustomerDTO customer, MachineDTO machine);
}
